﻿using BaseUi.Views.MainWindows;
using HandyControl.Controls;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi.Views.PlcView
{
    /// <summary>
    /// OutBoxTakePositionView.xaml 的交互逻辑
    /// </summary>
    public partial class OutBoxTakePositionView : UserControlBase
    {
        private StudentData viewModel = new StudentData();
        public SolidColorBrush RedColor = new SolidColorBrush(Color.FromRgb(255, 69, 0));
        public SolidColorBrush GreenColor = new SolidColorBrush(Color.FromRgb(173, 255, 47));
        public SolidColorBrush BoroColor = new SolidColorBrush(Color.FromRgb(220, 220, 220));
        public SolidColorBrush LemonChiffonColor = new SolidColorBrush(Color.FromRgb(255, 250, 205));
        public OutBoxTakePositionView()
        {
            InitializeComponent();
            DataContext = viewModel;
            viewModel.CommonViewModel = MainWindow4.viewModel.CommonViewModel;
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            getnewnumber();
        }
        

        private void outboxpButton_Click1g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click1g1z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("142", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click1g3z1(object sender, RoutedEventArgs e)
        {
            getnewnumber();
        }

        private void getnewnumber()
        {
            var ioi = LocalStatic.Plc.Read<Int16>("1");
            if (ioi.IsSucceed==false)
            {
                outboxpBox1g1.Text ="未接收";
            }
            else
            {
                outboxpBox1g1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("2");
            if (ioi.IsSucceed == false)
            {
                outboxpBox1g2.Text = "未接收";
            }
            else
            {
                outboxpBox1g2.Text = ioi.Value.ToString();
            }
            //outboxpBox1g1.Text = LocalStatic.Plc.Read<Int16>("1").Value.ToString();
            //outboxpBox1g2.Text = LocalStatic.Plc.Read<Int16>("2").Value.ToString();
        }

        private void outboxpButton_Click1g3z2(object sender, RoutedEventArgs e)
        {
            try
            {

                short ser = Convert.ToInt16(outboxpBox1g1.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("1", ser);
            ser = Convert.ToInt16(outboxpBox1g2.Text);
                var ioi1 = LocalStatic.Plc.Write<Int16>("2", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("回温层上传失败");
                }
                if (ioi1.IsSucceed == false)
                {
                    Growl.Error("回温列上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click1g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("55", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click1g4z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("74", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click1g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("39", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click1g6z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("109", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click2g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("56", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click2g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click2g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("50", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click2g3z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("72", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click2g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("37", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click2g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("108", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click3g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outboxpButton_Click3g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("143", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }

        }
    }
}
